clear
clear mata
clear matrix

cd ..         																	 /* Goes back to parent folder */

capture log close
log using "log\06_New_Deal.log", replace

mkdir /tmp                                                                       /* creates a temporary folder to store temp files */


*       Patriotism!

*       FIRST VERSION  June       7, 2022
*       THIS VERSION   June       7, 2022
*       LAST RUN       June       7, 2022

*       LAST REVISOR		AT

*       Log of revisions:

*       This prepares New Deal variables

********************************************************************************
****                      PLAN OF THE PROCEDURE                             ****
****                                                                        ****
****  1. Prepare raw data  												    ****
****  2. Merge both sources  												****
****  3. Label and save 							  					    ****
********************************************************************************

********************************************************************************
****  1. Prepare raw data  												    ****
********************************************************************************
do "code-build/01_Shopping_List.do"

********************************************************************************
****        a. Fisback                     								    ****
********************************************************************************
import excel rawdata\Fishback\nddist04.xls, sheet("nddist04") firstrow clear
keeporder STATE NDCODE NDEXP AAA RFC HOLC PWAF PBA PRA FCA MEAN9628 
save "tmp/Fishback0", replace

********************************************************************************
****         b. Price                                      				    ****
********************************************************************************
import excel "rawdata\Fishback\newdeal.xls" , sheet("newdeal" ) firstrow clear

ren COUNTY NDCODE
keeporder STATE NDCODE SSA_OA SSA_ADC

********************************************************************************
****  2. Merge both sources  												****
********************************************************************************
merge 1:1 STATE NDCODE using "tmp/Fishback0", nogen keep(mat)                      /* 1 obs only in new db (Yellowstone: dropped because it's all missing) */

ren STATE  stateicpsr
ren NDCODE countynd
destring *, replace

********************************************************************************
****  3. Label and save 							  					    ****
********************************************************************************
lab var stateicpsr "State code (ICPSR)"
lab var countynd   "County code (Fishback, Kantor & Wallis 2003)"
lab var NDEXP      "Total grants: RELIEF+PWA+PRA+PBA+AAA+FSARR+USHAH (Fishback et al. 2003)"
lab var AAA        "Agric. Adjust. Admin. grants (Fishback et al. 2003)"
lab var RFC        "Reconstruction Finance Corp. loans (Fishback et al. 2003)"
lab var HOLC       "Home Owners Loan Corporation loans (Fishback et al. 2003)"
lab var PWAF       "Public Works Admin. Federal grants (Fishback et al. 2003)"
lab var PBA        "Public Buildings Admin. grants (Fishback et al. 2003)"
lab var PRA        "Public Roads Admin. grants (Fishback et al. 2003)"
lab var FCA		   "Farm Credit Admin. loans (Fishback et al. 2003)"
lab var MEAN9628   "Mean Democratic vote share: 1898-1928 (Fishback et al. 2003)"
lab var SSA_OA     "Social Security Act grants: old age (Fishback et al. 2003)"
lab var SSA_ADC    "Social Security Act grants: aid to dependent children (Fishback et al. 2003)"

save "data\new_deal", replace

********************************************************************************
****  4. Erase junk      							  					    ****
********************************************************************************
erase "tmp/Fishback0.dta"

rmdir "tmp/"

log close
exit